using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_CommonPetTipsPabilityAttribute : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_CommonPetTipsPabilityAttribute
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExImage icon { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textTitle { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textValue { protected set; get; }
            public UnityEngine.GameObject costSlotRoot { protected set; get; }
            public UnityEngine.GameObject costSlot { protected set; get; }
            public UnityEngine.GameObject lockState { protected set; get; }
            public UnityEngine.GameObject lockStateBg { protected set; get; }
            public UnityEngine.CanvasGroup canvasGroup { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("icon", out var __tbv0);
                this.icon = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textTitle", out var __tbv1);
                this.textTitle = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textValue", out var __tbv2);
                this.textValue = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("costSlotRoot", out var __tbv3);
                this.costSlotRoot = __tbv3;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("costSlot", out var __tbv4);
                this.costSlot = __tbv4;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("lockState", out var __tbv5);
                this.lockState = __tbv5;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("lockStateBg", out var __tbv6);
                this.lockStateBg = __tbv6;
                __binding.TryGetVariableValue<UnityEngine.CanvasGroup>("canvasGroup", out var __tbv7);
                this.canvasGroup = __tbv7;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields
        private ListScrollAdapter<UIN_CommonNoElementCell> costSlots;
        #endregion fields

        #region properties

        protected UIB_UIN_CommonPetTipsPabilityAttribute ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_CommonPetTipsPabilityAttribute();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.costSlots = this.InitListScroll<UIN_CommonNoElementCell>(this.ui.costSlot, this.OnCostSlotChanged);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds

        public void Show(UIPetSlotType slotType, string iconAssetPath, string title, string value)
        {
            this.Show();
            this.ui.textTitle.text = title;
            this.ui.textValue.text = value;
            this.SetImageSprite(this.ui.icon, iconAssetPath);

            float alpha = slotType == UIPetSlotType.Unlock ? 0.5f : 1.0f;
            this.ui.canvasGroup.alpha = alpha;

            this.ShowLockState(slotType);
        }

        private void ShowLockState(UIPetSlotType slotType)
        {
            bool isActive = slotType > UIPetSlotType.Unlock;
            this.ui.lockState.SetActive(isActive);
            this.ui.lockStateBg.SetActive(isActive);
        }

        public void ShowSlot(int slotCount)
        {
            bool isActive = slotCount > 0;
            if (isActive)
            {
                this.costSlots.RefillCells(slotCount);
            }
            this.ui.costSlotRoot.SetActive(isActive);
        }

        private void OnCostSlotChanged(UIN_CommonNoElementCell item, int index)
        {
            item.Show();
        }
        #endregion methonds
    }
}
